package p2p.logic.connection;

import p2p.logic.connection.communication.Communication;

public class Connection implements Runnable{
	
	private Communication type;
	private Thread thread;
	private boolean isStoppable;

	
	public Connection(Communication type, boolean isStoppable){
		
		this.thread = Thread.currentThread();
		this.type = type;
		this.isStoppable = isStoppable;
		
	}
	
	@Override
	public void run() {
			
		if (isStoppable)
			while (this.thread != null)
				this.type.start();
		else
			if (type == null){
				System.out.println();
			}else 
				this.type.start();
		
	}
	
	public void stop(){
				
		this.thread = null;
		
		this.type.stop();
		
	}
	
}
